package com.housekeeping.housekeeping.advertisingmanagement.controller.product;/*
 * @author  pyh
 * @date  2021/1/22 0022 下午 9:50
 * @version 1.0
 * @since JDK1.8_241
 */

import com.housekeeping.housekeeping.advertisingmanagement.entity.Product;
import com.housekeeping.housekeeping.advertisingmanagement.service.ProductService;
import com.housekeeping.housekeeping.advertisingmanagement.service.impl.ProductServiceImpl;
import com.housekeeping.housekeeping.advertisingmanagement.utils.ResponseEntitys;
import com.housekeeping.housekeeping.advertisingmanagement.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/product/proUpdate")
public class ProUpdateController extends HttpServlet {
    private ProductService ps = new ProductServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求字符编码
        req.setCharacterEncoding("utf-8");
        //设置响应字符集
        resp.setContentType("text/html;charset=utf-8");
        int id = Integer.parseInt(req.getParameter("id"));
        ResponseEntitys<Product> entity = null;
        Product update = ps.update(id);
        if (update!=null){
            entity = ResponseEntitys.success(update);
        }else {
            entity = ResponseEntitys.error(400009, "修改失败");
        }
        //将状态响应给前端
        ResponseUtils.resp(resp,entity);
    }
}
